package com.matuw.android.adapter.recyclerview;

import android.content.Context;
import android.util.SparseArray;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.matuw.android.adapter.ViewHolder;


public class QinViewHolder extends RecyclerView.ViewHolder implements ViewHolder {

    private final SparseArray<View> cacheViews = new SparseArray<>(8);

    public QinViewHolder(@NonNull View itemView) {
        super(itemView);
    }

    @NonNull
    @Override
    public View get() {
        return itemView;
    }

    @SuppressWarnings("unchecked")
    @Override
    public <V extends View> V getView(int viewId) {
        View cacheView = cacheViews.get(viewId);
        if (cacheView == null) {
            V view = itemView.findViewById(viewId);
            cacheViews.put(viewId, view);
            return view;
        }
        return (V) cacheView;
    }

    @NonNull
    @Override
    public Context getContext() {
        return itemView.getContext();
    }
}
